package com.jincheng.web.controller.system;

import com.jincheng.common.annotation.Log;
import com.jincheng.common.core.controller.BaseController;
import com.jincheng.common.core.domain.AjaxResult;
import com.jincheng.common.core.page.TableDataInfo;
import com.jincheng.common.enums.BusinessType;
import com.jincheng.common.utils.poi.ExcelUtil;
import com.jincheng.system.domain.Registration;
import com.jincheng.system.service.IRegistrationService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动报名信息Controller
 *
 * @author DairyJay
 * @date 2024-12-29
 */
@RestController
@RequestMapping("/system/registration")
public class RegistrationController extends BaseController {
    private final IRegistrationService registrationService;

    public RegistrationController(IRegistrationService registrationService) {
        this.registrationService = registrationService;
    }
    /**
     * 查询活动报名信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(Registration registration) {
        startPage();
        List<Registration> list = registrationService.selectRegistrationList(registration);
        return getDataTable(list);
    }

    /**
     * 导出活动报名信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:registration:export')")
    @Log(title = "活动报名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Registration registration) {
        List<Registration> list = registrationService.selectRegistrationList(registration);
        ExcelUtil<Registration> util = new ExcelUtil<>(Registration.class);
        util.exportExcel(response, list, "活动报名信息数据");
    }

    /**
     * 获取活动报名信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:registration:query')")
    @GetMapping(value = "/{registrationId}")
    public AjaxResult getInfo(@PathVariable("registrationId") Long registrationId) {
        return success(registrationService.selectRegistrationByRegistrationId(registrationId));
    }

    /**
     * 新增活动报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:registration:add')")
    @Log(title = "活动报名信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Registration registration) {
        return toAjax(registrationService.insertRegistration(registration));
    }

    /**
     * 修改活动报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:registration:edit')")
    @Log(title = "活动报名信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Registration registration) {
        return toAjax(registrationService.updateRegistration(registration));
    }

    /**
     * 删除活动报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:registration:remove')")
    @Log(title = "活动报名信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{registrationIds}")
    public AjaxResult remove(@PathVariable Long[] registrationIds) {
        return toAjax(registrationService.deleteRegistrationByRegistrationIds(registrationIds));
    }
}
